package com.Hsu.demo.mapper;

import com.Hsu.demo.model.UserInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author Hsu琛君珩
 * @ClassName:UserInfo2Mapper
 * @date 2023-12-28
 * @apiNote
 * @Version: v1.0
 */

/**
 * 动态SQL联系
 */
@Mapper
public interface UserInfo2Mapper {
    @Insert("<script>" +
            "insert into userinfo (username,password,age," +
            "<if test='gender!=null'>gender,</if>" +
            "phone)" +
            " values(#{username},#{password},#{age}," +
            "<if test='gender!=null'>#{gender},</if>" +
            "#{phone})" +
            "</script>")
    Integer insert(UserInfo userInfo);

    Integer insertByXML(UserInfo userInfo);

    /**
     * where标签
     */
    List<UserInfo> selectByCondition(UserInfo userInfo);

    /**
     * trim标签
     */
    List<UserInfo> selectByCondition2(UserInfo userInfo);

    /**
     * 注解方式
     */
    @Select("<script>" +
            "select * from userinfo" +
            "        <where>" +
            "            <if test='username!=null'>" +
            "                username =#{username}" +
            "            </if>" +
            "            <if test='age!=null'>" +
            "                and age =#{age}" +
            "            </if>" +
            "            <if test='gender!=null'>" +
            "                and gender =#{gender}" +
            "            </if>" +
            "        </where>" +
            "</script>")
    List<UserInfo> selectByCondition3(UserInfo userInfo);

    /**
     * trim标签
      * @param userInfo
     * @return
     */
    Integer updateByCondition(UserInfo userInfo);

    /**
     * set标签
     * @param userInfo
     * @return
     */
    Integer updateByCondition2(UserInfo userInfo);


    //批量删除
    Integer batchDelete(List<Integer> ids);

}
